using UnityEngine;

namespace Framework
{
    public class FsmTransition
    {
        public string EventName { get; private set; }
        public string ToState;
        public float Progress { get; private set; }
        private FsmState toFsmState;
        private float transitionTime;
        private float time;
        public FsmTransition()
        {

        }
        public void Initialize(string stateName, string eventName, float time = 0f)
        {
            ToState = stateName;
            eventName ??= stateName;
            this.EventName = eventName;
            transitionTime = Mathf.Max(time, 0f);
        }
        public void Enter()
        {
            time = 0;
            Progress = 0f;
            if (this.transitionTime == 0f)
            {
                Progress = 1;
            }
        }
        public void Update(float deltaTime)
        {
            time += deltaTime;
            Progress = Mathf.Clamp01(time / transitionTime);
        }
        
        public FsmState ToFsmState
        {
            get
            {
                return this.toFsmState;
            }
            set
            {
                this.toFsmState = value;
            }
        }
    }
}